#include <iostream>
using namespace std;
int main()
{
	int a,b,c;
	int sum,i,t,db,date=0,sign=0;
	int max(int);
	for(i=1;i<=7;i++)
	{
		cin>>a>>b;
		if (a>=0 && a<10 && b>=0 && b<10)
		{
			sum = a + b;
			t = max(sum);
			if (t!=0 && sign==0)
			{
				date = i;
				db = t;
				sign = 1;
			}
			else if (t!=0 && sign!=0)
			{
				if (db>t || db==t) date = date;
				else if (db<t) date = i;
			}
			else if (t==0 && sign==0) date = 0;
			else if (t==0 && sign!=0) date = date;
		}
		else
		{
			cout<<"Wrong"<<endl;
			break;
		}
	}
	cout<<date<<endl;
	return 0;
}

int max(int x)
{
	int t;
	t = x>8 ?(t-8) :0;
	return t;
}
